import fetch from 'common/src/utils/fetch'
import UTILS from "common/src/utils/utils";
import baseUrl from './env';


/**
 * 查询老生注册审核列表数据
 * @param {Object} data
 */
function findOldStuInfoRegisterList(params) {
    return fetch({
        url: '/api/studentservice/studentInfo/findOldStuInfoRegisterList',
        method: 'post',
        data: params
    });
}

/**
 * 查询新生报到审核列表数据
 * @param {Object} data
 */
export function findNewStuInfoReportList(data){
    return fetch({
        url: '/api/studentservice/studentInfo/findNewStuInfoReportList',
        method: 'post',
        headers: { 'Content-Type': 'application/json' },
        data
    })
}

/**
 * 导出老生注册审核列表数据
 * @param {Object} params
 */
function findOldStuInfoRegisterListExport(params) {
    let url = "/api/studentservice/studentInfo/findOldStuInfoRegisterListExport";
    let remove_params = ["pageNum_", "pageSize_"];
    let queryParam = '';
    for(let key in params) {
        // 去掉分页
        if (remove_params.includes(key)) {
            continue;
        }
        // 去掉空参数
        if (params[key] == "") {
            continue;
        }
        queryParam += `${key}=${params[key]}&`;
    }
    window.open(`${url}?${queryParam}`);
}

/**
 * 导出学生报到状态列表数据（excel、dbf） 根据exportType判断 为空或者null为excel，dbfType时 dbf导出
 * @param {Object} params
 */
function findNewStuInfoReportListExport(params) {
    let url = baseUrl + "/studentInfo/findNewStuInfoReportListExport";
    let remove_params = ["pageNum_", "pageSize_"];
    let queryParam = '';
    for(let key in params) {
        // 去掉分页
        if (remove_params.includes(key)) {
            continue;
        }
        // 去掉空参数
        if (params[key] == "") {
            continue;
        }
        queryParam += `${key}=${params[key]}&`;
    }
    window.open(`${url}?${queryParam}`);
}

function updateReportOrRegisterStatus(studentId) {
    return fetch({
        url: '/api/studentservice/studentInfo/updateReportOrRegisterStatus',
        method: 'get',
        params: {
            'studentId':  studentId
        }
    });
}

// 扫码条形码获取学生相关信息
function findStuScanInfoByStuId(params) {
  return fetch({
      url: baseUrl + "/studentTempInfo/findStuScanInfoByStuId?studentId=" + params.studentId,
      method: 'get',
  });
}

// 录取通知书扫码查询
function findStuScanInfoList(params) {
  return fetch({
      url: baseUrl + '/studentTempInfo/findStuScanInfoList',
      method: 'post',
      data: params
  });
}


function  findStuScanInfoListExport (data) {
  return fetch({
    url: baseUrl + "/studentTempInfo/findStuScanInfoListExport",
    method: 'post',
    responseType: 'blob',
    data
  }).then(res => {
    UTILS.downloadFile(res, '录取通知书清单.xls', 'application/vnd.ms-excel;charset=utf-8');
  });
}


const studentCheckApi = {
    'findOldStuInfoRegisterList': findOldStuInfoRegisterList,
    'findNewStuInfoReportList': findNewStuInfoReportList,
    'updateReportOrRegisterStatus': updateReportOrRegisterStatus,
    'findOldStuInfoRegisterListExport': findOldStuInfoRegisterListExport,
    'findNewStuInfoReportListExport': findNewStuInfoReportListExport,
    'findStuScanInfoByStuId':findStuScanInfoByStuId,
    'findStuScanInfoList':findStuScanInfoList,
    'findStuScanInfoListExport':findStuScanInfoListExport
}

export default studentCheckApi;
